home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 11 - 1995 / 11.04 Apr 95 / TreeAppƒ / Eric's C++ Libraries / Interface Classes / CPPTreeArea.cp < prev    next >
Encoding:
Text File  |  1996-04-04  |  6.8 KB  |  231 lines  |  [TEXT/KAHL]

  1. /***************************************************** IMPLEMENTATION
  2.     DATE:    11/7/93
  3.     AUTHOR: Eric R. Rosé
  4.  
  5.     CLASS:  CPPTreeArea
  6.     
  7.     SUPERCLASS: CPPScrollArea, CPPVisualTree
  8.     
  9.         This C++ class manages a tree which lives inside a scrolling
  10.         area.
  11.     
  12. ********************************************************************/
  13.  
  14. #include <CPPTreeArea.h>
  15. #include <CPPWindow.h>
  16. #include <ToolboxTools.h>
  17.  
  18. /*-----------------------------------------------------------------*/
  19. /*------------------------ APPLY ROUTINES -------------------------*/
  20. /*-----------------------------------------------------------------*/
  21.  
  22. extern    void    SetSelectState (CPPTreeNode *theNode, long param);
  23.  
  24.     void    DoRectSelect (CPPTreeNode *theNode, long param)
  25.     /* use the 'modifiers' information passed in 'param' to determine */
  26.     /* how to alter the selection state of the passed in node */
  27.     {
  28.         CPPVisualTreeNode    *vNode = (CPPVisualTreeNode *)theNode;
  29.         
  30.         if (vNode)
  31.           {
  32.               if (CommandKeyDown(param))
  33.                 vNode->SetSelect(kSetSelect, FALSE, TRUE);
  34.               else
  35.               if (ShiftKeyDown(param))
  36.                 vNode->SetSelect(kToggleSelect, FALSE, TRUE);
  37.               else
  38.                 vNode->SetSelect(kSetSelect, FALSE, TRUE);
  39.           }
  40.           
  41.     }
  42.  
  43. /*-----------------------------------------------------------------*/
  44. /*------------------------ PUBLIC METHODS -------------------------*/
  45. /*-----------------------------------------------------------------*/
  46.  
  47.     CPPTreeArea::CPPTreeArea (CPPWindow *OurWindow,
  48.                           Rect *ViewArea,
  49.                           Rect *DestArea,
  50.                           Boolean UseHScroll,
  51.                           Boolean UseVScroll,
  52.                           short hStep, 
  53.                           short vStep,
  54.                           orientStyle orientation,
  55.                           justStyle justification,
  56.                           joinTypes join,
  57.                           short branchLength) :
  58.                  CPPVisualTree (OurWindow->GetWindow(),
  59.                                  topLeft(*DestArea),
  60.                                  orientation, justification,
  61.                                  join, branchLength),
  62.                  CPPScrollArea (OurWindow, ViewArea, DestArea,
  63.                                  UseHScroll, UseVScroll,
  64.                                  hStep, vStep)
  65.     {
  66.     
  67.     }
  68.  
  69. /*-----------------------------------------------------------------*/
  70.  
  71.     CPPTreeArea::CPPTreeArea (CPPWindow *OurWindow,
  72.                           Boolean UseHScroll,
  73.                           Boolean UseVScroll,
  74.                           short hStep, 
  75.                           short vStep,
  76.                           orientStyle orientation,
  77.                           justStyle justification,
  78.                           joinTypes join,
  79.                           short branchLength) :
  80.                  CPPVisualTree (OurWindow->GetWindow(),
  81.                                  topLeft((OurWindow->GetWindow())->portRect),
  82.                                  orientation, justification,
  83.                                  join, branchLength),
  84.                  CPPScrollArea (OurWindow, UseHScroll, UseVScroll,
  85.                                  hStep, vStep)
  86.     {
  87.     
  88.     }
  89.  
  90. /*-----------------------------------------------------------------*/
  91.  
  92.     CPPTreeArea::~CPPTreeArea (void)
  93.     {
  94.     
  95.     }
  96.  
  97. /*-----------------------------------------------------------------*/
  98.             
  99.     char *CPPTreeArea::ClassName (void)
  100.     {
  101.         return "CPPTreeArea";
  102.     }
  103.  
  104. /*-----------------------------------------------------------------*/
  105.             
  106.     Boolean    CPPTreeArea::Member (char *className)
  107.     {
  108.         if (strcmp(className, CPPTreeArea::ClassName()) == 0)
  109.           return TRUE;
  110.         else
  111.           if (CPPVisualTree::Member(className))
  112.             return TRUE;
  113.           else
  114.             return CPPScrollArea::Member(className);
  115.     }
  116.  
  117. /*-----------------------------------------------------------------*/
  118.     
  119.     Boolean    CPPTreeArea::DoScrollAreaClick (Point clickPt, short modifiers, 
  120.                                               Rect *selRect)
  121.     /* handle a click in the scroll area; clickPt is in area coordinates */
  122.     /* a rectangle encompassing the selected area is returned in selRect */
  123.     /* (this is in area coordinates) */
  124.     /* SUBCLASS SHOULD OVERRIDE */
  125.     {
  126.         Point    startPt = clickPt, 
  127.                 EndPt;
  128.         CPPVisualTreeNode    *theNode;
  129.         Boolean    wasDoubleClick = FALSE, selState = TRUE;
  130.                    
  131.              // first, check to see if the click was in a node
  132.              if (theNode = ((CPPVisualTreeNode *)this->topNode)->PointInNode (clickPt))
  133.                {
  134.                    // determine whether we have double-clicked on the node
  135.                    wasDoubleClick = (theNode == this->lastClicked) && 
  136.                                        (TickCount() - this->lastClickTime <= GetDblTime());
  137.                    this->lastClicked = theNode;
  138.                    this->lastClickTime = TickCount();
  139.                    
  140.                    if (wasDoubleClick)
  141.                      theNode->DoDoubleClick (modifiers);
  142.                    else
  143.                      {    // if the shift key is down, invert selection state
  144.                          if (ShiftKeyDown(modifiers))
  145.                            theNode->SetSelect(kToggleSelect, FALSE, TRUE);
  146.                          else
  147.                          // if the command key is down, add to selection
  148.                          if (CommandKeyDown (modifiers))
  149.                            theNode->SetSelect(kSetSelect, FALSE, TRUE);
  150.                          else
  151.                            {    // if no modifiers down, de-select all and select this one
  152.                                ApplyToFamily(this->topNode, SetSelectState, kClearSelect);
  153.                              theNode->SetSelect(kSetSelect, FALSE, TRUE);
  154.                            }
  155.                          theNode->DoSingleClick (modifiers);
  156.                      }
  157.                   return TRUE;
  158.                }
  159.              else    // the user did not click in a node.  De-select the current selection 
  160.                {        // if necessary, then let the user drag-select a new selection
  161.                    if (!ShiftKeyDown (modifiers) && 
  162.                        !CommandKeyDown(modifiers))
  163.                      ApplyToFamily(this->topNode, SetSelectState, kClearSelect);
  164.                  
  165.             // default behavior; scroll the area automatically as long
  166.             // as the mouse is down
  167.             if (CPPScrollArea::DoScrollAreaClick(clickPt, modifiers, selRect))
  168.               {
  169.                        // hilight all selected nodes
  170.                 if (this->topNode)
  171.                   ((CPPVisualTreeNode *)this->topNode)->DoOnFamilyInRect (selRect, 
  172.                                                               TRUE, DoRectSelect, modifiers);
  173.                        return TRUE;
  174.               }
  175.                    
  176.                }    // PtInRect
  177.              
  178.         return FALSE;
  179.     }
  180.  
  181. /*-----------------------------------------------------------------*/
  182.             
  183.     Boolean    CPPTreeArea::DoCommand (short commandID)
  184.     {
  185.         if (!CPPVisualTree::DoCommand(commandID))
  186.           return CPPScrollArea::DoCommand(commandID);
  187.         else
  188.           return TRUE;
  189.     }
  190.  
  191. /*-----------------------------------------------------------------*/
  192.             
  193.     void    CPPTreeArea::Draw (void)
  194.     {
  195.         CPPScrollArea::Draw();
  196.     }
  197.  
  198. /*-----------------------------------------------------------------*/
  199.  
  200.     void    CPPTreeArea::DrawContents (void)
  201.     {
  202.         this->isPrepared = TRUE;
  203.         this->preparedBy = (CPPVisualTree *)this;
  204.         
  205.         CPPVisualTree::Draw();
  206.         
  207.         this->isPrepared = FALSE;
  208.         this->preparedBy = NULL;
  209.     }
  210.  
  211.  
  212. /*-----------------------------------------------------------------*/
  213. /*---------------------- PROTECTED METHODS ------------------------*/
  214. /*-----------------------------------------------------------------*/
  215.  
  216.     void    CPPTreeArea::UserSpecificPrepare (void)
  217.     /* set the origin of the grafport before drawing */
  218.     /* SUBCLASS MAY OVERRIDE */ 
  219.     {
  220.         AdjustCoordinates();
  221.     }
  222.  
  223. /*-----------------------------------------------------------------*/
  224.  
  225.     void    CPPTreeArea::UserSpecificRestore (void)
  226.     /* restore the origin of the grafport after drawing */
  227.     /* SUBCLASS MAY OVERRIDE */ 
  228.     {
  229.         RestoreCoordinates();
  230.     }
  231.